package edu.gatech.fiveminutesleft.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.util.Base64;

/**
 * A static class with some useful cryptographic function wrappers.
 * 
 * @author Nick Johnson
 */
public class CryptoWrapper {

	/**
	 * Perform a SHA-256 hash on the input and return the base64 representation.
	 * 
	 * @param value
	 *            String to be hashed.
	 * @return Base64 string containing the SHA-245 hash of the input.
	 * @throws NoSuchAlgorithmException
	 */
	public static String secureHash(String value) {
		try {
			MessageDigest digest = MessageDigest.getInstance("SHA-256");

			digest.reset();
			byte hash[] = digest.digest(value.getBytes());

			return Base64.encodeToString(hash, Base64.NO_WRAP);
		} catch (NoSuchAlgorithmException exception) {
			throw new NullPointerException("SHA-256 has not on platfrom - App cannot contienu");
		}
	}

}
